home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 25.4 KB | 956 lines | [TEXT/MPS ] |
- /*
- File: Inspector.cp
-
- Contains: A test application class for testing the ASLM.
-
- Copyright: © 1991-1995 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
- #ifndef __FILES__
- #include <Files.h>
- #endif
- #ifndef __STANDARDFILE__
- #include <StandardFile.h>
- #endif
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
- #ifndef __LOWMEM__
- #include <LowMem.h>
- #endif
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
-
- #ifndef __TESTTOOL__
- #include <TestTool.h>
- #endif
- #ifndef __INSPECTOR__
- #include "Inspector.h"
- #endif
- #ifndef __WINDOWSTACKER__
- #include "WindowStacker.h"
- #endif
- #ifndef __INSPECTORCOMMON__
- #include "InspectorCommon.h"
- #endif
- #ifndef __REGISTEREDOBJECTSWINDOW__
- #include "RegisteredObjectsWindow.h"
- #endif
- #ifndef __LIBRARYMANAGERUTILITIES__
- #include <LibraryManagerUtilities.h>
- #endif
- #ifndef __STRING__
- #include <string.h>
- #endif
- #ifndef __STRINGS__
- #include <Strings.h>
- #endif
-
- /**********************************************************************
- ** PUBLIC Constructor
- ***********************************************************************/
-
- TInspector::TInspector(QDGlobals* qdPtr, BooleanParm initToolbox)
- : TApplication(qdPtr,initToolbox)
- {
- fVerbose = true;
- fDebug = false;
- fDoLoad = true;
- fGrowPool = true;
- fIterationCount = 1;
-
- OpenPrefsFile();
-
- fLibraryManagerCmd = kNoCmd;
- fUpdateListsScheduler = new TSerialScheduler;
- // we need to set the scheduler's client to ourself because the
- // TOperations are created by ASLM, but we want them to execute
- // in our global world and with us as the current client, not ASLM.
- fUpdateListsScheduler->SetSchedulerClient(::GetCurrentClient());
- fNextWindowLocation.v = kWindowVStart;
- fNextWindowLocation.h = kWindowHStart;
- fHTopWindowLocation = fNextWindowLocation.h + kWindowHResetStagger;
- GetLocalLibraryManager()->TraceLogOn();
-
- ::RegisterInspector(this);
-
- // read menus into menu bar
-
- long savedRefNum;
- GetLocalLibraryFile()->Preflight(savedRefNum);
- Handle menuBar = GetNewMBar(rMenuBar);
- DebugFailNULL(menuBar, resNotFound, "TInspector::InitInspector: could not get menubar.");
-
- // install menus
- SetMenuBar(menuBar);
- DisposeHandle(menuBar);
- // add DA names to Apple menu
- AppendResMenu(GetMenuHandle(mApple),'DRVR');
- DrawMenuBar();
- GetLocalLibraryFile()->Postflight(savedRefNum);
-
- // create empty mouse region
- fMouseRgn = NewRgn();
- // make sure we have a valid cursor region
- AdjustCursor();
- }
-
- TInspector::~TInspector()
- {
- Trace("Disposing TInspector\n");
-
- //
- // save all window sizes and locations in the prefs file
- //
- TDocumentLink* theDocLink = DocList()->FirstDoc();
- while (theDocLink)
- {
- ((TRegisteredObjectsWindow*)theDocLink->GetDoc())->SaveWindowLocation();
- theDocLink = theDocLink->GetNext();
- }
-
- ::RegisterInspector(NULL);
-
- fUpdateListsScheduler->Run(); // make sure all operations get processed first
- delete fUpdateListsScheduler;
-
- DisposeHandle(Handle(fMouseRgn));
-
- ClosePrefsFile();
- }
-
- /**********************************************************************
- ** PUBLIC DoIdle
- ***********************************************************************/
-
- void TInspector::DoIdle()
- {
- /* Make sure all of our TLists are up-to-date */
- fUpdateListsScheduler->Run();
- }
-
- /**********************************************************************
- ** PUBLIC AdjustMenus
- ***********************************************************************/
-
- // Enable and disable menus based on the current state. The
- // user can only select enabled menu items. We set up all the
- // menu items before calling MenuSelect or MenuKey, since
- // these are the only times that a menu item can be selected.
- // Note that MenuSelect is also the only time the user will
- // see menu items. This approach to deciding what enable/
- // disable state a menu item has the advantage of
- // concentrating all the decision-making in one routine, as
- // opposed to being spread throughout the application. Other
- // application designs may take a different approach that may
- // or may not be as valid.
-
- void ExactAppend(MenuHandle aMenu, Str255 aString)
- {
- unsigned char fillString[128];
- /* Since AppendMenu will interpret meta-characters, first append a menu item with */
- /* no meta-characters, but which has the same length as aString, then set the menu */
- /* item to astring (SetMenuItemText doesn't interpret meta-characters). */
- fillString[0] = aString[0];
- if (aString[0])
- memset(fillString + 1, 'a', aString[0]);
- AppendMenu(aMenu, fillString);
- SetMenuItemText(aMenu, CountMItems(aMenu), aString);
- }
-
- void TInspector::AdjustMenus(void)
- {
- WindowPtr frontmost;
- MenuHandle menu;
- Boolean undo;
- Boolean cutCopyClear;
- Boolean paste;
- short i; // menu item index
-
- frontmost = FrontWindow();
-
- long savedRefNum;
- GetLocalLibraryFile()->Preflight(savedRefNum);
-
- //
- // Edit menu
- //
-
- menu = GetMenuHandle(mEdit);
- DebugFailNULL(menu, resNotFound, "TInspector::AdjustMenus: could not get Edit menu.");
-
- undo = false;
- cutCopyClear = false;
- paste = false;
- if (frontmost != NULL) {
- if (fCurDoc == NULL) {
- undo = true; // all editing is enabled for DA windows
- cutCopyClear = true;
- paste = true;
- }
- }
-
- if (undo)
- EnableItem(menu, iUndo);
- else
- DisableItem(menu, iUndo);
-
- if (cutCopyClear) {
- EnableItem(menu, iCut);
- EnableItem(menu, iCopy);
- EnableItem(menu, iClear);
- }
- else {
- DisableItem(menu, iCut);
- DisableItem(menu, iCopy);
- DisableItem(menu, iClear);
- }
- if (paste)
- EnableItem(menu, iPaste);
- else
- DisableItem(menu, iPaste);
-
- //
- // File Menu
- //
-
- menu = GetMenuHandle(mFile);
- DebugFailNULL(menu, resNotFound, "TInspector::AdjustMenus: could not get File menu.");
- if (frontmost != NULL)
- EnableItem(menu,iClose);
- else
- DisableItem(menu,iClose);
-
- //
- // Windows Menu
- //
-
- menu = GetMenuHandle(mWindows);
- DebugFailNULL(menu, resNotFound, "TInspector::AdjustMenus: could not get Windows menu.");
-
- /* remove all documents from the Windows menu */
- for (i=CountMItems(menu); i>=kWindowListStart; i--)
- DeleteMenuItem(menu, i);
-
- /* add all the documents to the Windows menu */
- int numItems = kWindowListStart-1;
- TDocumentLink *theLink = DocList()->FirstDoc();
- while (theLink)
- {
- TDocument *theDoc = theLink->GetDoc();
- Str255 tempString;
- GetWTitle(theDoc->GetDocWindow(),tempString);
- ExactAppend(menu,tempString);
- theLink = theLink->GetNext();
- numItems++;
- CheckItem(menu,numItems,fCurDoc == theDoc);
- fWindowsMenuDocList[numItems-kWindowListStart] = theDoc;
- }
-
- //
- // Tests Menu
- //
-
- menu = GetMenuHandle(mTests);
- DebugFailNULL(menu, resNotFound, "TInspector::AdjustMenus: could not get Tests menu.");
-
- CheckItem(menu, iVerbose, fVerbose);
- CheckItem(menu, iDebug, fDebug);
- CheckItem(menu, iDoLoad, fDoLoad);
- CheckItem(menu, iGrowPool, fGrowPool);
-
- /* remove all tests from the Tests menu */
- for (i=CountMItems(menu); i>=kTestsListStart; i--)
- {
- delete fTestsMenuTestList[i-kTestsListStart];
- DeleteMenuItem(menu, i);
- }
-
- /* add all the tests to the Tests menu */
- TClassID* testname;
- size_t testnamelen;
- size_t testToolPrefixLen = strlen(kTestToolPrefix);
- OSErr err;
- TClassInfo* info = GetClassInfo(ClassID(kTTestToolID), &err);
-
- fNumTests = 0;
- if (info)
- {
- while ((testname = (TClassID*)info->Next()) != NULL)
- {
- testnamelen = strlen(*testname);
- fTestsMenuTestList[fNumTests] = new (testnamelen) TClassID(*testname);
- DebugFailNULL(fTestsMenuTestList[fNumTests], kASLMOutOfMemoryErr,
- "TInspector::AdjustMenus: could not allocate TClassID*.");
- Str255 itemname;
- memmove(&itemname[1], (char*)testname + testToolPrefixLen, testnamelen - testToolPrefixLen + 1);
- itemname[0] = testnamelen - testToolPrefixLen + 1;
- ExactAppend(menu,itemname);
- if (++fNumTests >= kMaxTests)
- break;
- }
- delete info;
- }
-
- GetLocalLibraryFile()->Postflight(savedRefNum);
- }
-
- /**********************************************************************
- ** PUBLIC AdjustCursor
- ***********************************************************************/
-
- void TInspector::AdjustCursor()
- {
- SetCursor(&fqd->arrow);
- }
-
- /**********************************************************************
- ** isKeyDown
- ***********************************************************************/
-
- #define kOptionKeyCode 58
-
- static Boolean isKeyDown(long keyCode)
- {
- KeyMap keys;
- Byte *keysBytes;
-
- GetKeys(keys);
-
- keysBytes = (Byte *)keys;
-
- return((keysBytes[keyCode/8] & (1 << keyCode % 8)) != 0);
- }
-
- /*******************************************************************************
- ** ChooseFolderItemHandler
- **
- ** Custom item handler for selecting directories. We use a modified SFGetFile
- ** dialog which has a "Select Current Folder" button and a "Select" button.
- ********************************************************************************/
-
- SFReply gChooseFolderReply;
- short gSFVRefNum;
- long gSFDirID;
-
- static pascal short ChooseFolderItemHandler(short item, DialogPtr theDialog)
- {
- // constants for items passed to this dialog handler
- const short selectHilitedFolderButton = 11; /* item number for the "Select Current Directory" button */
- const short selectCurrentFolderButton = 13; /* item number for the "Select" button */
- const escapeKey = 0x1000 + 27; /* "item" number for the escape key */
-
- short itemType; /* type of the SFGetFile Open button */
- Handle itemHdl; /* handle to SFGetFile Open button item */
- Rect itemRect; /* rect of the SFGetFile Open button */
- short newState; /* the new Hilite state to set the "select" button to */
-
- /* if no directory is selected then dim the "Select" button. Otherwise */
- /* just turn it on normally. */
-
- /* the fType field of the Reply record will contain the DirID of the hilited */
- /* folder if one is hilited. Otherwise it will contain 0. */
- if (gChooseFolderReply.fType == 0)
- newState = 255; /* dim the "select" button */
- else
- newState = 0; /* turn on the "select" button */
-
- /* Only set the hilite state and redraw if the state has changed. This */
- /* prevents the button from flickering. */
- GetDialogItem(theDialog, selectHilitedFolderButton, &itemType, &itemHdl, &itemRect);
- if (newState != (**(ControlHandle)itemHdl).contrlHilite)
- {
- HiliteControl(ControlHandle(itemHdl), newState);
- Draw1Control(ControlHandle(itemHdl));
- };
-
- /* act on the item hit */
- switch (item)
- {
- case escapeKey: /* if they hit the escape key then generate a cancel */
- return getCancel;
-
- case selectHilitedFolderButton: /* the "Select Current Folder" button was pressed */
- case selectCurrentFolderButton: /* the "Select" button was pressed */
- {
- /* The user has made his choice of folders. We need to put the volume of the */
- /* folder into gSavSFVolume and the DirID into gSavSFDirID. */
-
- gSFVRefNum = -LMGetSFSaveDisk(); /* get the current volume */
-
- /* If the "select" button has been pressed then choose the hilited folder. */
- /* The DirID of the hilited folder is always in the fType filed of the reply */
- /* record. */
- if (item == selectHilitedFolderButton)
- gSFDirID = (long)gChooseFolderReply.fType;
-
- /* otherwise we want the currently opened folder whose DirID is stored in */
- /* the low memory global "CurDirStor". */
- else
- gSFDirID = LMGetCurDirStore();
-
- /* tell SFPGetFile to "open" the folder, "open" meaning "select" not enter */
- return getOpen;
- }
-
- default: /* Normally, we just return the item */
- return item;
- }
- }
-
- /*******************************************************************************
- ** MySFFileFilter
- **
- ** This filter is used when we are selecting a folder. Since
- ** we don't want to display any files we always return TRUE.
- ********************************************************************************/
-
- static pascal Boolean MySFFileFilter( ParmBlkPtr)
- {
- return true;
- };
-
- /**********************************************************************
- ** PUBLIC DoMenuCommand
- ***********************************************************************/
-
- // This is called when an item is chosen from the menu bar (after calling
- // MenuSelect or MenuKey). It does the right thing for each command.
-
- // static TDynamic* gExampleObject;
-
- void TInspector::DoMenuCommand(short menuID, short menuItem)
- {
- short itemHit;
- Str255 daName;
- short daRefNum;
- WindowPtr window;
-
- window = FrontWindow();
- switch (menuID) {
- case mApple:
- switch (menuItem) {
- case iAbout: // bring up alert for About
- itemHit = Alert(rAboutAlert, NULL);
- break;
- default: // all non-About items in this menu are DAs et al
- long savedRefNum;
- GetLocalLibraryFile()->Preflight(savedRefNum);
- GetMenuItemText(GetMenuHandle(mApple), menuItem, daName);
- GetLocalLibraryFile()->Postflight(savedRefNum);
- daRefNum = OpenDeskAcc(daName);
- break;
- }
- break;
-
- case mFile:
- switch (menuItem) {
- case iQuit:
- Terminate();
- break;
- case iClose:
- if (fCurDoc != NULL) {
- HideWindow(fCurDoc->GetDocWindow());
- }
- else
- CloseDeskAcc(((WindowPeek) fWhichWindow)->windowKind);
- // make sure our current document/window references are valid
- fWhichWindow = FrontWindow();
- if (fWhichWindow != NULL) {
- fCurDoc = fDocList->FindDoc(fWhichWindow);
- SetPort(fWhichWindow);
- }
- else
- fCurDoc = NULL;
- break;
- }
- break;
-
- case mEdit: // call SystemEdit for DA editing & MultiFinder
- if (!SystemEdit(menuItem-1))
- DebugBreak("Oops. SystemEdit returned false.");
- break;
-
- case mWindows: {
- switch (menuItem) {
- case iStack: {
- fNextWindowLocation.v = kWindowVStart;
- fNextWindowLocation.h = kWindowHStart;
- TRY
- TWindowStacker* stacker = new TWindowStacker(kWindowHStagger, kWindowVStagger);
- if (stacker)
- stacker->StackWindows(fNextWindowLocation.h,fNextWindowLocation.v);
- delete stacker;
- CATCH_ALL
- AlertUser(kInspectorErrStrings, kWindowStackerLibraryMissing);
- ENDTRY
- }
- break;
-
- case iRefresh:
- {
- TRegisteredObjectsWindow* theWindow =
- (TRegisteredObjectsWindow*)DocList()->FindDoc(FrontWindow());
- if (theWindow)
- theWindow->UpdateList();
- }
-
- #if 0
- if (gExampleObject == NULL)
- gExampleObject = (TDynamic*)GetLocalLibraryManager()->NewObject(ClassID("appl:exam$TExampleClass,1.1"),NULL,::GetSystemPool());
- else
- {
- delete gExampleObject;
- gExampleObject = NULL;
- }
- #endif
- break;
-
- case iRefreshAll:
- {
- TDocumentLink* theDocLink = DocList()->FirstDoc();
- while (theDocLink)
- {
- ((TRegisteredObjectsWindow*)theDocLink->GetDoc())->UpdateList();
- theDocLink = theDocLink->GetNext();
- }
- }
- break;
-
- case iHome:
- {
- TRegisteredObjectsWindow* theWindow = (TRegisteredObjectsWindow*)DocList()->FindDoc(FrontWindow());
- if (theWindow)
- theWindow->HomeWindow();
- }
- break;
-
- default:
- TDocument* theDoc = fWindowsMenuDocList[menuItem-kWindowListStart];
- if (theDoc)
- {
- ShowWindow(theDoc->GetDocWindow());
- SelectWindow(theDoc->GetDocWindow());
- }
- break;
- }
-
- }
- break;
-
- case mCommands:
- switch (menuItem) {
- case iRegisterFolder:
- {
- SFTypeList typelist;
- Point where = {100,150};
- long savedRefNum;
- GetLocalLibraryFile()->Preflight(savedRefNum);
-
- FileFilterUPP theFileFilterUPP = NewFileFilterProc(MySFFileFilter);
- DlgHookUPP theDialogHookUPP = NewDlgHookProc(ChooseFolderItemHandler);
- SFPGetFile(where,(ConstStr255Param)"\p",theFileFilterUPP,0,typelist,theDialogHookUPP,
- &gChooseFolderReply,rFolderDialog,NULL);
- DisposeRoutineDescriptor(theFileFilterUPP);
- DisposeRoutineDescriptor(theDialogHookUPP);
-
- GetLocalLibraryFile()->Postflight(savedRefNum);
- if (gChooseFolderReply.good)
- {
- TMacFileSpec fileSpec(gSFVRefNum, gSFDirID, (unsigned char *)"\p");
- OSErr result = RegisterLibraryFileFolder(&fileSpec);
- if (result)
- DebugBreak("RegisterLibraryFileFolder failed");
- }
- break;
- }
- case iUnregisterFolder:
- {
- SFTypeList typelist;
- Point where = {100,150};
- long savedRefNum;
- GetLocalLibraryFile()->Preflight(savedRefNum);
-
- FileFilterUPP theFileFilterUPP = NewFileFilterProc(MySFFileFilter);
- DlgHookUPP theDialogHookUPP = NewDlgHookProc(ChooseFolderItemHandler);
- SFPGetFile(where,(ConstStr255Param)"\p",theFileFilterUPP,0,typelist,theDialogHookUPP,
- &gChooseFolderReply,rFolderDialog,NULL);
- DisposeRoutineDescriptor(theFileFilterUPP);
- DisposeRoutineDescriptor(theDialogHookUPP);
-
- GetLocalLibraryFile()->Postflight(savedRefNum);
- if (gChooseFolderReply.good)
- {
- TMacFileSpec fileSpec(gSFVRefNum, gSFDirID, (unsigned char *)"\p");
- OSErr result = UnregisterLibraryFileFolder(
- &fileSpec, isKeyDown(kOptionKeyCode));
- if (result)
- DebugBreak("UnregisterLibraryFileFolder failed");
- }
- break;
- }
- case iRegisterFile:
- {
- SFTypeList typelist;
- Point where = {100,150};
- SFReply reply;
- SFGetFile(where,(ConstStr255Param)"\pSelect a library file",NULL,-1,typelist,NULL,&reply);
- if (reply.good)
- {
- TMacFileSpec fileSpec(0,0,reply.fName);
- long procID;
- GetWDInfo(reply.vRefNum,&fileSpec.fVRefNum,&fileSpec.fParID, &procID);
- TLibraryFile* libFile;
- OSErr result = RegisterLibraryFile(&fileSpec, &libFile);
- if (result)
- DebugBreak("RegisterLibraryFile failed");
- else
- {
- char namebuffer[256];
- Trace("Library file registered: %s\n",libFile->GetVerboseName(namebuffer));
- }
- }
- break;
- }
- case iUnregisterFile:
- {
- SFTypeList typelist;
- Point where = {100,150};
- SFReply reply;
- SFGetFile(where,(ConstStr255Param)"\pSelect a library file",NULL,-1,typelist,NULL,&reply);
- if (reply.good)
- {
- TMacFileSpec fileSpec(0,0,reply.fName);
- long procID;
- GetWDInfo(reply.vRefNum,&fileSpec.fVRefNum,&fileSpec.fParID, &procID);
- OSErr result = UnregisterLibraryFileByFileSpec(&fileSpec, false);
- if (result)
- DebugBreak("UnregisterLibraryFileByFileSpec failed");
- }
- break;
- }
- case iReloadLibraryManager:
- fLibraryManagerCmd = kReloadLibraryManagerCmd;
- ExitLoop();
- break;
- case iUnloadLibraryManager:
- fLibraryManagerCmd = kUnloadLibraryManagerCmd;
- ExitLoop();
- break;
- case iGotoSimpleProgram:
- fLibraryManagerCmd = kGotoSimpleProgramCmd;
- ExitLoop();
- break;
- case iTraceLogOn:
- GetLocalLibraryManager()->TraceLogOn();
- break;
- case iTraceLogOff:
- GetLocalLibraryManager()->TraceLogOff();
- break;
- }
- break;
-
- case mTests: {
- switch (menuItem) {
- case iVerbose:
- {
- fVerbose = !fVerbose;
- }
- break;
-
- case iDebug:
- {
- fDebug = !fDebug;
- }
- break;
-
- case iDoLoad:
- {
- fDoLoad = !fDoLoad;
- }
- break;
-
- case iGrowPool:
- {
- fGrowPool = !fGrowPool;
- }
- break;
-
- case iRunAllTests:
- {
- size_t idx = 0;
- RgnHandle myRgn = NewRgn(); // a region to use for WaitNextEvent
- while (idx < fNumTests)
- {
- RunTest(fTestsMenuTestList[idx++]);
- EventRecord myEvent;
- WaitNextEvent(nullEvent, &myEvent, 0, myRgn);
- }
- DisposeRgn(myRgn);
- }
- break;
-
- default:
- {
- TClassID* theTest = fTestsMenuTestList[menuItem-kTestsListStart];
- RunTest(theTest);
- }
- break;
- }
-
- }
- break;
- }
-
- HiliteMenu(0); // unhighlight what MenuSelect (or MenuKey) hilited
- }
-
- /**********************************************************************
- ** PUBLIC DoNew
- ***********************************************************************/
-
- // Create a new document and window.
-
- void TInspector::DoNew(TRegisteredObjects *theObjects)
- {
- if (fDocList->NumDocs() == kMaxDocuments)
- return;
-
- TRegisteredObjectsWindow* tDoc;
-
- tDoc = new TRegisteredObjectsWindow(rDocWindow, theObjects, this);
- // if we didn't get an allocation error, add it to list
- if (tDoc != NULL) {
- fDocList->AddDoc(tDoc);
-
- //
- // Relocate the window. If this there is no saved info and this windows
- // location then RestoreWindowLocation will return false.
- //
- if (!tDoc->RestoreWindowLocation())
- {
- tDoc->MoveWindow(fNextWindowLocation.h,fNextWindowLocation.v);
- tDoc->SizeWindow(kWindowHSizeStart, kWindowVSizeStart);
- fNextWindowLocation.h +=kWindowHStagger;
- fNextWindowLocation.v +=kWindowVStagger;
- if ((fNextWindowLocation.v > fqd->screenBits.bounds.bottom-60) ||
- (fNextWindowLocation.h > fqd->screenBits.bounds.right-60))
- {
- fNextWindowLocation.v = kWindowVStart;
- fNextWindowLocation.h = fHTopWindowLocation;
- fHTopWindowLocation += kWindowHResetStagger;
- }
- }
- ShowWindow(tDoc->GetDocWindow());
- }
- }
-
- /**********************************************************************
- ** PUBLIC Terminate
- ***********************************************************************/
-
- // Clean up the application and exits. You might want to close all
- // of your documents (and ask the user to save them) here.
-
- void TInspector::Terminate()
- {
- ExitLoop();
- }
-
- /**********************************************************************
- ** PUBLIC OpenPrefsFile
- ***********************************************************************/
-
- #if GENERATINGPOWERPC
- #define kInspectorPrefs "\pInspectorPPC Prefs"
- #else
- #define kInspectorPrefs "\pInspector Prefs"
- #endif
-
- void TInspector::OpenPrefsFile()
- {
- long dirID;
- short vRefNum;
- OSErr err = FindFolder(-1, kPreferencesFolderType, true, &vRefNum, &dirID);
- if (err)
- fPrefsFileRefNum = -1;
- else
- {
- HCreateResFile(vRefNum, dirID, (ConstStr255Param) kInspectorPrefs);
- fPrefsFileRefNum = HOpenResFile(vRefNum, dirID,
- (ConstStr255Param) kInspectorPrefs, fsRdWrPerm);
- }
- }
-
- /**********************************************************************
- ** PUBLIC ClosePrefsFile
- ***********************************************************************/
-
- void TInspector::ClosePrefsFile()
- {
- if (fPrefsFileRefNum != -1)
- CloseResFile(fPrefsFileRefNum);
- }
-
- /**********************************************************************
- ** PUBLIC GetPrefsFileRefNum
- ***********************************************************************/
-
- short TInspector::GetPrefsFileRefNum()
- {
- return fPrefsFileRefNum;
- }
-
- /**********************************************************************
- ** PUBLIC RunTest
- ***********************************************************************/
-
- static void Idle(RgnHandle myRgn)
- {
- EventRecord myEvent;
- WaitNextEvent(nullEvent, &myEvent, 0, myRgn);
- }
-
- static int _CDECL myPrintFunc(const char* format, char* args)
- {
- char outstring[256];
- int ret = SLMvsprintf(outstring, format, args);
- Trace(outstring);
- return ret;
- }
-
- void TInspector::RunTest(TClassID* testname)
- {
- RgnHandle myRgn = NewRgn(); // a region to use for WaitNextEvent
- TTestTool* tool = NULL;
- OSErr theErr;
- TStandardPool* thePool;
- TPoolNotifier* savedNotifier;
-
- Idle(myRgn);
-
- if (fVerbose)
- Trace("INFO: Creating Tool %s\n", testname);
-
- if (fDoLoad)
- {
- if (fDebug)
- DebugStr((ConstStr255Param)"\pAbout to load class");
- theErr = LoadClass(*testname, true);
- if (theErr != kNoError)
- {
- Trace("###LoadClass failed, error = %d\n", theErr);
- return;
- }
- }
- else if (fDebug)
- DebugStr((ConstStr255Param)"\pAbout to new tool");
-
- thePool = GetLocalPool();
- savedNotifier = thePool->GetNotifier();
- if (!fGrowPool)
- thePool->SetNotifier(NULL);
-
- tool = (TTestTool*)NewObjectWithParent(*testname, ClassID(kTTestToolID), &theErr);
- if (theErr != kNoError)
- Trace("###NewObject Error %d\n", theErr);
-
- if (tool == NULL)
- Trace("### ERROR: Could not create Tool %s\n", testname);
- else
- {
- tool->SetPool(thePool);
- tool->SetPrintf(myPrintFunc);
-
- long count = fIterationCount;
-
- if (fVerbose)
- {
- Trace("****************** Begin Test *****************\n");
- PoolInfo info;
- thePool->GetPoolInfo(info);
- Trace("INFO: Pool size = %d\n", info.fFreeBytes);
- Trace("INFO: Largest Block = %d\n", info.fLargestBlock);
- }
-
- tool->InitTest(fVerbose, fDebug, 0, NULL);
- Idle(myRgn);
- while (count--)
- {
- tool->RunTestIteration(fVerbose, fDebug);
- Idle(myRgn);
- }
- tool->EndTest(fVerbose, fDebug);
- Idle(myRgn);
-
- if (fVerbose)
- Trace("INFO: Destroying Tool %s\n", testname);
- if (fDebug)
- DebugStr((ConstStr255Param)"\pAbout to destroy tool");
- delete tool;
-
- if (fVerbose)
- {
- PoolInfo info;
- thePool->GetPoolInfo(info);
- Trace("INFO: Pool size = %d\n", info.fFreeBytes);
- Trace("INFO: Largest Block = %d\n", info.fLargestBlock);
- if (!fGrowPool)
- {
- void* test = thePool->Allocate(kInspectorPoolSize*2);
- if (test != NULL)
- {
- Trace("ERROR: Allocated block larger than pool size!\n");
- thePool->GetPoolInfo(info);
- Trace("ERROR: Pool size = \n", info.fFreeBytes);
- Trace("ERROR: Largest Block = \n", info.fLargestBlock);
- thePool->Free(test);
- thePool->GetPoolInfo(info);
- Trace("ERROR: Pool size = \n", info.fFreeBytes);
- Trace("ERROR: Largest Block = \n", info.fLargestBlock);
- }
- else
- {
- thePool->GetPoolInfo(info);
- Trace("INFO: After freeing chunks -->");
- Trace("INFO: Pool size = \n", info.fFreeBytes);
- Trace("INFO: Largest Block = \n", info.fLargestBlock);
- }
- }
- }
- Idle(myRgn);
- }
-
- if (fVerbose)
- Trace("****************** End Test *****************\n");
-
- if (fDoLoad)
- UnloadClass(*testname);
-
- DisposeRgn(myRgn);
- }
-